const rp = require('request-promise');
// const _ = require('lodash');

// var appkey = '24813666';
// var secret = '564438cbb9bdfefa4cd3d09b57bdd584';
// var code = 'be150a235df148b2a256553f478fdefb';

module.exports = class extends think.Service {
  async getImageInfo(url) {
    try {
      // 获取 session
      const options = {
        method: 'POST',
        uri: 'https://aiperson.market.alicloudapi.com/ai_market/ai_ocr_universal/shen_fen_zheng/v1',
        headers: {
          'Authorization': 'APPCODE be150a235df148b2a256553f478fdefb'
        },
        form: {
          'IMAGE_TYPE': '1',
          'IMAGE': url
        }
      };

      const sessionData = await rp(options);

      // sessionData = JSON.parse(sessionData);
      // if (!sessionData.openid) {
      //   return null;
      // }
      return sessionData;
    } catch (e) {
      return null;
    }
  }
};
